﻿using System;
using System.Collections;
using System.Security.Principal;
using System.Web;
using System.Web.Caching;
using System.Web.Profile;
using System.Web.SessionState;

namespace RoketSolutions.SP2010.Infrostructure.UI.Ajax.Abstractions
{
    public class HttpContextWrapper
    {
        public HttpContextWrapper(HttpContext context)
        {
            HttpContext = context;
        }

        public HttpContextWrapper()
        {
            
        }

        public HttpContext HttpContext { get; set; }

        #region / Wrapped Properties /

        RequestWrapper _request;
        public virtual RequestWrapper Request
        {
            get { return _request ?? ( _request = new RequestWrapper(HttpContext.Request)); 
            }
            set { _request = value; }
        }

        ResponseWrapper _response;
        public virtual ResponseWrapper Response
        {
            get { return _response ?? (_response = new ResponseWrapper(HttpContext.Response)); }
            set { _response = value; }
        }

        #endregion

        #region / Properties /

        public Exception[] AllErrors
        {
            get { return HttpContext.AllErrors; }
        }

        public HttpApplicationState Application
        {
            get { return HttpContext.Application; }
        }

        public HttpApplication ApplicationInstance
        {
            get { return HttpContext.ApplicationInstance; }
            set { HttpContext.ApplicationInstance = value; }
        }

        public Cache Cache
        {
            get { return HttpContext.Cache; }
        }

        public IHttpHandler CurrentHandler
        {
            get { return HttpContext.CurrentHandler; }
        }

        public RequestNotification CurrentNotification
        {
            get { return HttpContext.CurrentNotification; }
        }

        public Exception Error
        {
            get { return HttpContext.Error; }
        }

        public IHttpHandler Handler
        {
            get { return HttpContext.Handler; }
            set { HttpContext.Handler = value; }
        }

        public bool IsCustomErrorEnabled
        {
            get { return HttpContext.IsCustomErrorEnabled; }
        }

        public bool IsDebuggingEnabled
        {
            get { return HttpContext.IsDebuggingEnabled; }
        }

        public bool IsPostNotification
        {
            get { return HttpContext.IsPostNotification; }
        }

        public IDictionary Items
        {
            get { return HttpContext.Items; }
        }

        public IHttpHandler PreviousHandler
        {
            get { return HttpContext.PreviousHandler; }
        }

        public ProfileBase Profile
        {
            get { return HttpContext.Profile; }
        }

        public HttpServerUtility Server
        {
            get { return HttpContext.Server; }
        }

        public HttpSessionState Session
        {
            get { return HttpContext.Session; }
        }

        public bool SkipAuthorization
        {
            get { return HttpContext.SkipAuthorization; }
            set { HttpContext.SkipAuthorization = value; }
        }

        public DateTime Timestamp
        {
            get { return HttpContext.Timestamp; }
        }

        public TraceContext Trace
        {
            get { return HttpContext.Trace; }
        }

        public IPrincipal User
        {
            get { return HttpContext.User; }
            set { HttpContext.User = value; }
        }

        #endregion

        #region / Methods /

        public void AddError(Exception errorInfo)
        {
            HttpContext.AddError(errorInfo);
        }

        public void ClearError()
        {
            HttpContext.ClearError();
        }

        #endregion

    }
}